home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech's Sprocket™ / Sprocket (original from 1994) / SprocketSample / SprocketSample.cp < prev    next >
Encoding:
Text File  |  1994-12-06  |  6.8 KB  |  327 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        SprocketSample.cp
  3.  
  4.     Contains:    Boilerplate application-specific code.
  5.                 
  6.     Written by: Dave Falkenburg
  7.  
  8.     Copyright:    © 1993-94 by Dave Falkenburg, all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.      
  12.          <7>     12/6/94    DRF        Gave this file a better name. Also stop defining kCreditsBox
  13.                                     here.
  14.          <6>     11/8/94    DRF        (LDR) Modified to pass all non-standard menu selections through
  15.                                     to window obj.
  16.          <5>     11/8/94    DRF        DoEditMenu is gone; call DoMenuSelection instead.
  17.          <4>     9/28/94    DRF        Changes for Dave Mark: More comments & rearranged code.
  18.          <3>     9/27/94    DRF        Changes for Dave Mark: AppLib.h is now Sprocket.h &
  19.                                      clipboard conversion routines are fixed.
  20.          <2>      9/9/94    DRF        Reorganized headers and removed redundant #includes and
  21.                                     conditionalized AOCE support.
  22.  */
  23.  
  24. #include "Sprocket.h"
  25. #include "Window.h"
  26. #include "StandardMenus.h"
  27. #include "SplashWindow.h"
  28.  
  29. #include <Desk.h>
  30. #include <Resources.h>
  31. #include <Errors.h>
  32.  
  33. #include "ToolWindow.h"
  34. #include "DocWindow.h"
  35. #include "PreferencesDialogWindow.h"
  36. #include "MailableDocWindow.h"
  37.  
  38. AppPreferences    gPreferences;
  39.  
  40. //    Function Prototypes:
  41.  
  42. void    AboutBox(void);
  43. void    OpenExistingDocument(void);
  44.  
  45.  
  46. #define    mDebug                            256
  47. #define        iNewMailableWindow            1
  48.  
  49. #define    kAboutBoxFor68K                    256
  50. #define    kAboutBoxForPowerPC                257
  51. #define        iCreditsButton                2
  52.  
  53.  
  54. ////////////////////////////////////////////////////////////////////
  55. //
  56. //    SetupApplication
  57. //
  58. //    Modify this function to provide any application-specific
  59. //    initialization you may require.
  60. //
  61. //    This is a good place to call EnterMovies, allocate
  62. //    sound channels, setup network things, etc.
  63.  
  64. OSErr
  65. SetupApplication(void)
  66.     {    
  67.     InsertMenu(GetMenu(mDebug),0);                //    Add Debug Menu
  68.  
  69. #if    qAOCEAware
  70.     if (gHasAOCE)
  71.         EnableItem(GetMHandle(mDebug),1);
  72. #endif
  73.  
  74.     TToolWindow    * someTools = new TToolWindow(1025);
  75.  
  76.     gPreferences.fMailPreferences.fCreateMailerForNewDocuments = true;
  77.  
  78.     InitCursor();
  79.     return (noErr);
  80.     }
  81.  
  82.  
  83. ////////////////////////////////////////////////////////////////////
  84. //
  85. //    TearDownApplication
  86. //
  87. //    Modify this function to tear down anything that you allocated
  88. //    from within SetupApplication.
  89.  
  90. void
  91. TearDownApplication(void)
  92.     {
  93.     }
  94.  
  95.  
  96. ////////////////////////////////////////////////////////////////////
  97. //
  98. //    HandleMenu
  99. //
  100. //    Modify this function to handle any menu commands you might add
  101. //    to Sprocket’s default menubar. This isn’t the greatest strategy,
  102. //    but works for most things.
  103.  
  104. void
  105. HandleMenu(TWindow * topWindowObj, long menuCode)
  106.     {
  107.     short    menu = (short) (menuCode >> 16);
  108.     short    item = (short) (menuCode & 0xffff);
  109.     Str255    deskAccName;
  110.     
  111.     switch (menu)
  112.         {
  113.         case    mApple:
  114.             switch (item)
  115.                 {
  116.                 case    iAbout:
  117.                     AboutBox();
  118.                     break;
  119.                     
  120.                 default:
  121.                     GetItem(GetMHandle(mApple),item,deskAccName);
  122.                     (void) OpenDeskAcc(deskAccName);
  123.                     break;
  124.                 }
  125.             break;
  126.             
  127.         case    mFile:
  128.             switch (item)
  129.                 {
  130.                 case    iNew:
  131.                     CreateNewDocument();
  132.                     break;
  133.                 
  134.                 case    iOpen:
  135.                     OpenExistingDocument();
  136.                     break;
  137.                 
  138.                 case    iClose:
  139.                     HandleClose(FrontNonFloatingWindow());
  140.                     break;
  141.                     
  142.                 case    iPreferences:
  143.                     TPreferencesDialogWindow * prefsDialog = new TPreferencesDialogWindow;
  144.                     break;
  145.  
  146.                 case    iQuit:
  147.                     gDone = true;
  148.                     break;
  149.                     
  150.                 default:
  151.                     break;
  152.                 }
  153.             break;
  154.         
  155.         case    mEdit:
  156.             switch (item)
  157.                 {
  158.                 case    iShowOrHideClipboard:
  159.                     break;
  160.                     
  161.                 default:
  162.                     if ((!SystemEdit(item-1)) && (topWindowObj != nil))
  163.                         topWindowObj->DoMenuSelection(menu,item);
  164.                     break;
  165.                 }
  166.         
  167.         case    mDebug:
  168.             switch(item)
  169.                 {
  170.                 case    iNewMailableWindow:
  171. #if    qAOCEAware
  172.                     TMailableDocWindow *aWackyThing = new TMailableDocWindow;
  173. #endif
  174.                     break;
  175.                     
  176.                 default:
  177.                     break;
  178.                 }
  179.             break;
  180.             
  181.         default:
  182.             if (topWindowObj != nil)
  183.                 topWindowObj->DoMenuSelection(menu, item);
  184.             break;
  185.         }
  186.     }
  187.  
  188.  
  189. ////////////////////////////////////////////////////////////////////
  190. //
  191. //    ReadLocalClipboardFromScrap & WriteLocalClipboardToScrap
  192. //
  193. //    These functions will be called whenever the user switches into
  194. //    or out of your application.
  195. //
  196. //    If you keep copy of the clipboard in your own data structures,
  197. //    these functions will allow you to keep it in synch so that the
  198. //    user can cut and paste information between your program and
  199. //    other applications.
  200. //
  201. //    We don’t actually use the clipboard in Sprocket, so these
  202. //    functions are empty for now.
  203.  
  204. void
  205. ReadLocalClipboardFromScrap(void)
  206.     {
  207.     }
  208.  
  209. void
  210. WriteLocalClipboardToScrap(void)
  211.     {
  212.     }
  213.  
  214.  
  215. ////////////////////////////////////////////////////////////////////
  216. //
  217. //    CreateNewDocument, OpenDocument, PrintDocument, and
  218. //    QuitApplication.
  219. //
  220. //    These functions will be called whenever one of the required
  221. //    AppleEvents is sent to your application— either when your
  222. //    program is launched, or when the user opens a document from
  223. //    the Finder.
  224.  
  225. OSErr
  226. CreateNewDocument(void)
  227.     {
  228.     TDocWindow    *aNewWindow = new TDocWindow();
  229.     
  230.     if (aNewWindow)
  231.         return noErr;
  232.     else
  233.         return memFullErr;
  234.     }
  235.  
  236.  
  237. OSErr
  238. OpenDocument(LetterDescriptor * /* theDocument */, void * /*unused*/)
  239.     {
  240.     //    Normally, you would open the file (or letter) and use the
  241.     //    information to create windows, etc.
  242.     
  243.     //    For now, we just create a new document.
  244.  
  245.     return CreateNewDocument();
  246.     }
  247.  
  248.  
  249. OSErr
  250. PrintDocument(LetterDescriptor * /* theDocument */, void * /*unused*/)
  251.     {
  252.     //    We don’t do printing yet, but you could.
  253.     return errAEEventNotHandled;
  254.     }
  255.  
  256.  
  257. Boolean
  258. QuitApplication(void)
  259.     {
  260.     //    Just go ahead and say we’re done quitting…
  261.     
  262.     //    Normally, you would offer to close any unsaved documents,
  263.     //    allowing the user to cancel along the way.
  264.  
  265.     return true;
  266.     }
  267.  
  268.  
  269.  
  270. ////////////////////////////////////////////////////////////////////
  271. //
  272. //    AboutBox
  273. //
  274. //    Put up our about box, including the version number. Depending
  275. //    on what version we are running, pick the correct DLOG resource.
  276. //
  277.  
  278. void
  279. AboutBox(void)
  280.     {
  281.     Handle            versionHandle;
  282.     StringPtr        nullStr = (StringPtr) "\p";
  283.     StringPtr        shortVersionString = nullStr;
  284.     short            itemHit;
  285.     
  286.     versionHandle = GetResource('vers',1);
  287.     if (versionHandle)
  288.         shortVersionString = (StringPtr) ((char *) *versionHandle + 6);
  289.     ParamText(shortVersionString,nullStr,nullStr,nullStr);
  290.     ReleaseResource(versionHandle);
  291.  
  292. #ifndef    powerc
  293.     itemHit = StandardAlert(kAboutBoxFor68K);
  294. #else
  295.     itemHit = StandardAlert(kAboutBoxForPowerPC);
  296. #endif
  297.  
  298.     if (itemHit == iCreditsButton)
  299.         StandardAlert(kCreditsBox);
  300.     }
  301.  
  302.  
  303.  
  304. ////////////////////////////////////////////////////////////////////
  305. //
  306. //    OpenExistingDocument
  307. //
  308. //    Use StandardFile to ask the user for a file to open. We use
  309. //    CustomGetFile so that we can properly handle update events
  310. //    in other windows while the dialog is active.
  311.  
  312. void
  313. OpenExistingDocument(void)
  314.     {
  315.     StandardFileReply    reply;
  316.     SFTypeList            ourTypes;
  317.     
  318.     Point    where = { -1, -1 };
  319.     
  320.     HiliteWindowsForModalDialog(false);
  321.     CustomGetFile((FileFilterYDUPP) nil, -1, ourTypes, &reply, 0, where,
  322.                   (DlgHookYDUPP) nil,StandardDialogFilterYD, nil,nil,nil);
  323.     HiliteWindowsForModalDialog(true);
  324.     }
  325.  
  326.  
  327.